﻿{include file='pub/header'/}
<title>商品列表</title>
</head>
<body class="pos-r">
<div>
    <nav class="breadcrumb">{$breadNav}</nav>
    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px"
                   onclick="addGood();" href="javascript:;" title="添加商品">
                <i class="Hui-iconfont Hui-iconfont-add"></i>添加商品
            </a>
            </span>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
               href="javascript:location.replace(location.href);" title="刷新">
                <i class="Hui-iconfont">&#xe68f;</i>
            </a>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-bg table-hover table-sort">
                <thead>
                <tr class="text-c">
                    <th width="40">商品货号</th>
                    <th width="60">缩略图</th>
                    <th width="100">产品名称</th>
                    <th width="100">单价</th>
                    <th width="100">积分</th>
                    <th width="100">库存</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $list as $k=>$good}
                <tr class="text-c va-m">
                    <td>{$good.gno}</td>
                    <td>
                        <a onClick="picture_show('查看图片', '{$good.image}')" data-src="" href="javascript:;">
                            <img width="60" class="product-thumb" src="{$good.image}">
                        </a>
                        <form action="{:url('score_image')}" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="id" value="{$good.id}">
                            <label for="{$k}" style="font-size: 10px;">
                                <input class="btn btn-primary" name="file" style="display: none;" type="file" id="{$k}"
                                       onchange="uploadimg(this)"/>更改图片
                            </label>
                        </form>

                    </td>
                    <td>
                        {$good.good_name}
                    </td>
                    <td>
                        {$good.good_price}
                    </td>
                    <td>
                        {$good.score}
                    </td>
                    <td>
                        <span>
                        <input type="text" value="{$good.num}" class="input-text" style="width: 100px;"/>
                        <button type="button" class="radius btn-primary btn" onclick="saveRem(this, '{$good.id}')">保存</button>
                        </span>
                    </td>
                    <td class="td-manage">
                        <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'{$good.id}')"
                           href="javascript:;" title="删除">
                            <i class="Hui-iconfont">&#xe6e2;</i>删除
                        </a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
        </div>
    </div>
</div>

{include file='pub/footer'/}
<script type="text/javascript">
    $('.table-sort').dataTable();

    //添加商品
    function addGood() {
        layer_show("添加商品", '{:url("gift")}');
    }


    /*图片-查看*/
    function picture_show(title, url, id) {
        var imgsurl = url.split(',');
        var content = '';
        $.each(imgsurl, function (i, v) {
            content += "<img style='width: 120px; margin: 10px;' src='" + v + "'/>";
        });
        var index = layer.open({
            type: 1,
            title: title,
            content: content
        });
        layer.full(index);
    }


    /*产品-删除*/
    function product_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.post("{:url('Products/score_del')}", {idstr: id}, function (res) {
                if (res.code == 1) {
                    layer.msg('删除成功');
                    $(obj).parents('tr').remove();
                } else {
                    layer.msg(res.msg);
                }
            });
        });
    }

    function uploadimg(o) {
        $(o).parents('form').ajaxSubmit(function (res) {
            if (res.code == 1) {
                location.reload();
            } else {
                layer.msg(res.msg);
            }
        });
    }
    function saveRem(o, id){
        var num = $(o).siblings('input').val();
        $.post("{:url('saveRem')}", {id:id, num:num}, function (res) {
            if(res.code == 1){
                location.reload();
            }
            layer.msg(res.msg);
        })
    }

</script>
</body>
</html>